/* Original Author:  Dominick O'Dierno
 * Date: 2007   odiernod@gmail.com     --Originally intended for use with DOMercury:  http://www.odierno.com/domercury
 * Description: Provides the Zip action for an ItemsList
 * 
 * --CHANGELOG--
 * 
 * */
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;
using DOMercury.Interfaces;
using DOMercury.Items;

namespace DOMercury.Actions
{
    class ZipAction : IAction
    {
        #region IAction Members

        public string ActionType
        {
            get { return "Zip"; }
        }

        public string Description
        {
            get { return "Zip with 7Zip"; }
        }

        public string ParamDescription
        {
            get { return "Optional Archive Name"; }
        }

        public string ParameterType
        {
            get { return "Command Line"; }
        }

        public bool Perform(IItem item, object specialParams)
        {
            try
            {
                ItemsList filenames = (ItemsList)item;
                string aName = (string)specialParams;
                if (aName.Trim().Length <= 0)
                {
                    if (filenames.Items.Count > 0)
                    {
                        aName = "\"" + filenames.Items[0].Path + ".zip\"";
                    }
                    else
                    {
                        MessageBox.Show("No Files Selected");
                        return false;
                    }
                }
                else
                {
                    string direc = System.IO.Path.GetDirectoryName(filenames.Items[0].Path);
                    aName = direc + "\\" + aName + ".zip";
                }
                string argstring = "a -tzip \"" + aName + "\" ";

                foreach (PathItem pi in filenames.Items)
                {
                    argstring += "\"" + pi.Path + "\" ";
                }

                System.Diagnostics.Process.Start("7za", argstring);
                return true;
            }
            catch
            {
                return false;
            }
        }

        #endregion
    }
    
}
